From: kfraser@localhost.localdomain Date: Fri, 28 Jul 2006 16:04:55 +0000 (+0100) Subject: [NET] back: Replace netif->status with netif_carrier_ok X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15773 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/%22bookmarks:/?a=commitdiff_plain;h=648ad07608c62e15343bb8834d86600223fbbec2;p=xen.git [NET] back: Replace netif->status with netif_carrier_ok The connection status to the frontend can be represented using netif_carrier_ok instead of netif->status. As a result, we delay the construction of the dev qdisc until the carrier comes on. This is a prerequisite for adding a tx queue. By the same token, netif->active is now simply the conjunction of netif_running and netif_carrier_ok so it too can be removed. Because netif_carrier_off/netif_carrier_on and rtnl_lock all entail memory barriers, there is no need to have extra memory barriers around them. Signed-off-by: Herbert Xu --- diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/common.h b/linux-2.6-xen-sparse/drivers/xen/netback/common.h index c52aaa5f6c..3ba0251dca 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h @@ -86,8 +86,6 @@ typedef struct netif_st { struct timer_list credit_timeout; /* Miscellaneous private stuff. */ - enum { DISCONNECTED, DISCONNECTING, CONNECTED } status; - int active; struct list_head list; /* scheduling list */ atomic_t refcnt; struct net_device *dev; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c index f52e2601b7..b5decfd3ea 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c @@ -36,28 +36,20 @@ static void __netif_up(netif_t *netif) { - struct net_device *dev = netif->dev; - netif_tx_lock_bh(dev); - netif->active = 1; - netif_tx_unlock_bh(dev); enable_irq(netif->irq); netif_schedule_work(netif); } static void __netif_down(netif_t *netif) { - struct net_device *dev = netif->dev; disable_irq(netif->irq); - netif_tx_lock_bh(dev); - netif->active = 0; - netif_tx_unlock_bh(dev); netif_deschedule_work(netif); } static int net_open(struct net_device *dev) { netif_t *netif = netdev_priv(dev); - if (netif->status == CONNECTED) + if (netif_carrier_ok(dev)) __netif_up(netif); netif_start_queue(dev); return 0; @@ -67,7 +59,7 @@ static int net_close(struct net_device *dev) { netif_t *netif = netdev_priv(dev); netif_stop_queue(dev); - if (netif->status == CONNECTED) + if (netif_carrier_ok(dev)) __netif_down(netif); return 0; } @@ -93,11 +85,12 @@ netif_t *netif_alloc(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN]) return ERR_PTR(-ENOMEM); } + netif_carrier_off(dev); + netif = netdev_priv(dev); memset(netif, 0, sizeof(*netif)); netif->domid = domid; netif->handle = handle; - netif->status = DISCONNECTED; atomic_set(&netif->refcnt, 1); init_waitqueue_head(&netif->waiting_to_free); netif->dev = dev; @@ -256,11 +249,9 @@ int netif_map(netif_t *netif, unsigned long tx_ring_ref, netif->rx_req_cons_peek = 0; netif_get(netif); - wmb(); /* Other CPUs see new state before interface is started. */ rtnl_lock(); - netif->status = CONNECTED; - wmb(); + netif_carrier_on(netif->dev); if (netif_running(netif->dev)) __netif_up(netif); rtnl_unlock(); @@ -296,20 +287,13 @@ static void netif_free(netif_t *netif) void netif_disconnect(netif_t *netif) { - switch (netif->status) { - case CONNECTED: + if (netif_carrier_ok(netif->dev)) { rtnl_lock(); - netif->status = DISCONNECTING; - wmb(); + netif_carrier_off(netif->dev); if (netif_running(netif->dev)) __netif_down(netif); rtnl_unlock(); netif_put(netif); - /* fall through */ - case DISCONNECTED: - netif_free(netif); - break; - default: - BUG(); } + netif_free(netif); } diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 6795bcd3af..80d16b7576 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -143,7 +143,7 @@ int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev) BUG_ON(skb->dev != dev); /* Drop the packet if the target domain has no receive buffers. */ - if (!netif->active || + if (unlikely(!netif_running(dev) || !netif_carrier_ok(dev)) || (netif->rx_req_cons_peek == netif->rx.sring->req_prod) || ((netif->rx_req_cons_peek - netif->rx.rsp_prod_pvt) == NET_RX_RING_SIZE)) @@ -404,7 +404,9 @@ static void add_to_net_schedule_list_tail(netif_t *netif) return; spin_lock_irq(&net_schedule_list_lock); - if (!__on_net_schedule_list(netif) && netif->active) { + if (!__on_net_schedule_list(netif) && + likely(netif_running(netif->dev) && + netif_carrier_ok(netif->dev))) { list_add_tail(&netif->list, &net_schedule_list); netif_get(netif); }